import { BasicColumn, FormSchema } from "/@/components/Table"
import { rules } from "/@/utils/helper/validator"
import { render } from "/@/utils/common/renderUtils"
import { listCashierTags, listPayPassage } from "/@/api/pay"
import {} from "/@/enum/pageEnums"

export enum ConfigPageType {
  JSON = "1",
  CUSTOM = "2",
}

export const columns: BasicColumn[] = [
  {
    title: "支付方式代码",
    width: 100,
    dataIndex: "wayCode",
  },
  {
    title: "支付方式名称",
    width: 100,
    dataIndex: "wayName",
  },
  {
    dataIndex: "status",
    title: "状态",
    width: 40,
    customRender: ({ text }) => {
      let color = "green"
      if (text == "0") color = "#FFCC33"
      if (text == "1") color = "green"

      return render.renderTag(render.renderDict(text, "data_use_status"), color)
    },
  },
]

export const cashierConfigColumns: BasicColumn[] = [
  {
    dataIndex: "sourceName",
    title: "来源",
    helpMessage: ["收银台会通过来源获取可用的支付列表", "收银台来源字典code: pay_order_source"],
    width: 220,
    customRender: ({ text }) => {
      const color = "green"
      return render.renderTag(text, color)
    },
  },
  {
    title: "默认",
    dataIndex: "isDefault",
    width: 60,
    customRender: ({ text }) => {
      const color = text === "1" ? "orange" : "cyan"
      return render.renderTag(render.renderDict(text, "bool_value"), color)
    },
  },
  {
    title: "支付接口",
    width: 120,
    dataIndex: "ifName",
  },
  {
    title: "支付方式代码",
    width: 150,
    dataIndex: "wayCode",
  },
  {
    title: "支付方式名称",
    width: 150,
    dataIndex: "wayName",
  },
]

export const cashierConfigFormSchema: FormSchema[] = [
  {
    field: "id",
    label: "",
    component: "Input",
    show: false,
  },
  {
    field: "appId",
    label: "",
    component: "Input",
    show: false,
  },
  {
    field: "passageId",
    label: "支付通道",
    required: true,
    component: "ApiSelect",
    dynamicDisabled: ({ values }) => {
      return !!values.id
    },
  },
  {
    field: "isDefault",
    label: "默认",
    required: true,
    component: "JDictSelectTag",
    defaultValue: "0",
    componentProps: {
      type: "radio",
      dictType: "bool_value",
    },
  },
  {
    field: "source",
    label: "来源",
    component: "JDictSelectTag",
    componentProps: {
      showSearch: true,
      dictType: "pay_order_source",
    },
  },
  {
    field: "remark",
    label: "备注",
    component: "InputTextArea",
    componentProps: {
      autoSize: {
        minRows: 3,
        maxRows: 8,
      },
    },
  },
]

export const formSchema: FormSchema[] = [
  {
    field: "id",
    label: "通道id",
    show: false,
    component: "Input",
  },
  {
    field: "canRelate",
    label: "是否能被引用",
    show: false,
    component: "RadioButton",
  },

  {
    field: "status",
    label: "状态",
    required: true,
    component: "JDictSelectTag",
    colProps: { span: 12 },
    componentProps: {
      dictType: "data_use_status",
      type: "radio",
    },
  },
  {
    field: "rate",
    label: "支付方式费率",
    required: true,
    defaultValue: 0,
    colProps: { span: 12 },
    helpMessage: "单位是%",
    component: "Input",
  },
  {
    field: "remark",
    label: "备注",
    componentProps: {},
    component: "InputTextArea",
    colProps: {
      style: "color: red",
      sm: 24, // ≥576px
    },
  },
  {
    field: "relateId",
    label: "引用其他通道配置",
    slot: "relateOtherPassage",
    ifShow: ({ model, field }) => model["canRelate"],
    helpMessage: [
      "1. 当多个通道需要使用同一个配置后, 为了便于维护这里可以直接设置成引用其他通道配置",
      "2. 比如支付宝的条码支付, 手机网站和条码支付可以公用一个配置手机网站配置",
    ],
    component: "Input",
  },
]
